﻿# CoffeeScript
@Cofe ?= {}

utils = Cofe.utils

# MODEL - Represents a Atom Feed Item.
class Event extends Spine.Model
  # id - feed item unique id
  @configure 'Event', 'id', 'title', 'author', 'categories', 'links'

  constructor: ->
    super

  
  # Construct Event from Atom feed item.
  Event.fromXml = (data) ->        
    
    id = $(data).find('guid:first').text()
    title = $(data).children('title').text()
    author = $(data).children('author').text()       
    description = $(data).children('description').text()       
    
    categories = {}
    for c in $(data).children('category')      
      pc = utils.parseCategory(c)
      categories[pc.type] =  pc.value

    links = {}
    for l in $(data).children('a10\\:link')
      link = utils.parseLink(l)
      links[link.rel] = link
    #categories = (utils.parseCategory(c) for c in $(data).find('category'))
    #links = (utils.parseLink(l) for l in $(data).find('link'))

    new Event({
      id : id
      author : author
      categories : categories
      links : links
      title : title
      description : description
    })


Cofe.Event = Event
